#ifndef _LT_INPUT_MANAGER_H_
#define _LT_INPUT_MANAGER_H_

#include <OIS/OIS.h>
#include <list>
#include "fastsig/fastsig.hpp"
#include "ltKeyboardListener.h"
#include "ltMouseListener.h"
#include "ltSingleton.h"

namespace Ogre
{
	class RenderWindow;
}

namespace OIS
{
	class InputManager;
}

namespace Lotus
{
	class LOTUS_API InputManager:Utilities::Singleton<InputManager>, public OIS::KeyListener, public OIS::MouseListener, public Ogre::WindowEventListener
	{
	public:
		InputManager();		
		virtual ~InputManager();
		LT_DECLARE_SINGLETON(InputManager);

		bool init(Ogre::RenderWindow& ogreRenderWindow,bool showMouseCursor=false);
		void InputManager::showMouseCursor(bool show);

		void setInputEnabled(bool enabled);
		bool isInputEnabled() const;

		OIS::Keyboard*     getKeyboard() const;
		OIS::Mouse*        getMouse()    const;

		void addKeyboardListener(Lotus::KeyboardListener* listener);
		void removeKeyboardListener(Lotus::KeyboardListener* listener);

		void addMouseListener(Lotus::MouseListener* listener);
		void removeMouseListener(Lotus::MouseListener* listener);

		fastsig::signal<void (const OIS::KeyEvent&)>						KeyPressedEvent;
		fastsig::signal<void (const OIS::KeyEvent&)>						KeyReleasedEvent;

		fastsig::signal<void (const OIS::MouseEvent&)>						MouseMovedEvent;
		fastsig::signal<void (const OIS::MouseEvent&, OIS::MouseButtonID)>  MousePressedEvent;
		fastsig::signal<void (const OIS::MouseEvent&, OIS::MouseButtonID)>  MouseReleasedEvent;
	
	protected:
		OIS::InputManager* oisInputManager;
		OIS::Keyboard*	   oisKeyboard;
		OIS::Mouse*        oisMouse;

	private:
		bool keyPressed(const OIS::KeyEvent& arg);
		bool keyReleased(const OIS::KeyEvent& arg);
		bool mouseMoved(const OIS::MouseEvent& arg);
		bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
		bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
		void windowResized(Ogre::RenderWindow* ogreRenderWindow);
		void inputUpdate(const Ogre::FrameEvent& evt);

		fastsig::connection updateConnection;
		bool inputEnabled;
		std::list<Lotus::KeyboardListener*> KeyListenerList;
		std::list<Lotus::MouseListener*> MouseListenerList;
	};
}

#endif